import 'package:flutter/material.dart';

/// int 扩展 .px方法 使用下面的getPx方法
extension IntPx on int {
  double get px => ScreenHelper.getPx(toDouble());
}

/// double 扩展.px方法 使用下面的getPx方法
extension DoublePx on double {
  double get px => ScreenHelper.getPx(this);
}

class ScreenHelper {
  static late MediaQueryData _mediaQueryData;
  static late double screenWidth;
  static late double screenHeight;
  static late double ratio;

  static void init(BuildContext context, {double baseSize = 375}) {
    _mediaQueryData = MediaQuery.of(context);
    screenWidth = _mediaQueryData.size.width;
    screenHeight = _mediaQueryData.size.height;
    ratio = screenWidth / baseSize;
  }

  static double getPx(double size) {
    return size * ratio;
  }
}
